import router from './index'
import { showToast } from 'vant'

const whiteList = ['/login', '/verify'] // 白名单

router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token')

    if (token) {
        if (to.path === '/login') {
            next('/')
        } else {
            next()
        }
    } else {
        if (whiteList.includes(to.path) || to.meta.noAuth) {
            next()
        } else {
            showToast('请先登录')
            next(`/login?redirect=${to.path}`)
        }
    }
}) 